package com.zyy.smartcity1129.zhdj;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.youth.banner.Banner;
import com.youth.banner.indicator.CircleIndicator;
import com.zyy.smartcity1129.BaseFragment;
import com.zyy.smartcity1129.R;
import com.zyy.smartcity1129.data.IconInfo;
import com.zyy.smartcity1129.util.BannerAd;
import com.zyy.smartcity1129.util.RvAd;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ZhFragment extends BaseFragment {
    private Banner bannerZH;
    private RecyclerView rvZH1;

    @Override
    protected int layId() {
        return R.layout.f_zh;
    }

    @Override
    protected String title() {
        return "智慧党建";
    }

    @Override
    protected boolean back() {
        return false;
    }

    @Override
    protected Boolean bottom() {
        return true;
    }

    @Override
    protected void init(View iv) {
        initView(iv);
        bannerZH.setAdapter(new BannerAd(
                Arrays.asList(R.drawable.a1, R.drawable.a2, R.drawable.a3, R.drawable.a4)
        )).setBannerRound(16).addBannerLifecycleObserver(this).setLoopTime(3000).setIndicator(
                new CircleIndicator(getContext())
        ).start();
        rvZH1.setLayoutManager(new GridLayoutManager(getContext(), 5));
        List<IconInfo> list = new ArrayList<>();
        list.add(new IconInfo("党建动态", R.drawable.djdt));
        list.add(new IconInfo("党员学习", R.drawable.dyxx));
        list.add(new IconInfo("组织活动", R.drawable.zzhd));
        list.add(new IconInfo("建言献策", R.drawable.jyxc));
        list.add(new IconInfo("随手拍", R.drawable.ssp));
        RvAd<IconInfo> rvAd = new RvAd<IconInfo>(list, R.layout.r_all) {
            private void initView(View vi) {
                image = (ImageView) vi.findViewById(R.id.image);
                tv1 = (TextView) vi.findViewById(R.id.tv1);
            }

            private TextView tv1;
            private ImageView image;

            @Override
            protected void initR(View vi, IconInfo iconInfo, int p) {
                initView(vi);
                Glide.with(getContext()).load(iconInfo.getImg()).into(image);
                tv1.setText(iconInfo.getName());
                vi.setOnClickListener(view -> {
                    switch (p) {
                        case 0:
                            add(new DJDynamicFragment());
                            break;
                        case 1:
                            add(new DYLearnFragment());
                            break;
                        case 2:
                            add(new ZZActivitiesFragment());
                            break;
                        case 3:
                            add(new DJFeedbackFragment());
                            break;
                        case 4:
                            add(new DJPhotographFragment());
                            break;
                    }
                });
            }
        };
        rvZH1.setAdapter(rvAd);
    }

    private void initView(View iv) {
        bannerZH = (Banner) iv.findViewById(R.id.bannerZH);
        rvZH1 = (RecyclerView) iv.findViewById(R.id.rvZH1);
    }
}
